Skip to content

fix(start-plan): system blocks + proactive jsdom captcha - #4

Closed
yurchik228336 wants to merge 1 commit into
TriDefender:auto-captchafrom
yurchik228336:fix/start-plan-captcha-system-prompt
Closed

yurchik228336 wants to merge 1 commit into
TriDefender:auto-captchafrom
yurchik228336:fix/start-plan-captcha-system-prompt

Conversation

@yurchik228336

Copy link
Copy Markdown
Contributor

Summary

Fixes #2 — start-plan JWT works on billing but /v1/messages failed with:

  • 3007 without captcha
  • 3012 with solved captcha but missing official ZCode gateway system blocks

This PR ports a tested fix (verified live against zcode.z.ai):

  1. Inject official ZCode system gateway blocks (positions 0/1) on every start-plan Anthropic request — without these upstream returns 3012 "method not allowed"
  2. Proactive traceless Aliyun captcha via jsdom + AliyunCaptcha.js (scene 11xygtvd): cache ~45s, attach x-aliyun-captcha-verify-param before request, re-solve + retry once on captcha rejection
  3. Bearer JWT auth for start-plan Anthropic (instead of x-api-key)

Replaces Playwright-based reactive-only captcha flow on auto-captcha with a lighter jsdom solver that matches ZCode desktop behaviour.

Test plan

  • cd captcha_node && npm install
  • node scripts/test-start-plan.mjs — captcha + chat with system blocks → HTTP 200, model reply received
  • TriDefender: plan: start-plan + OAuth JWT → POST /v1/messages streams successfully

…ptcha

Fixes TriDefender#2 — start-plan /v1/messages returned 3007 without
captcha and 3012 with solved captcha but missing ZCode gateway system blocks.

- Prepend official system blocks on every start-plan Anthropic request
- Proactive traceless Aliyun captcha via jsdom (scene 11xygtvd), ~45s cache
- Bearer JWT auth for start-plan; retry once on captcha rejection
@TriDefender

Copy link
Copy Markdown
Owner

I am reviewing this and comparing it to a local (not pushed) patch will be back shortly

@TriDefender

Copy link
Copy Markdown
Owner

Code review

Found 4 issues:

  1. solveCaptcha(challenge) is not wrapped in try/catch inside retryStartPlanIfNeeded. If the jsdom solver throws (timeout, crash), the error escapes as an unhandled rejection instead of returning a controlled error response. The surrounding calls (getProactiveCaptchaHeaders() and the retry fetch) are both protected, but this one is not.

};
}
const challenge = detectCaptchaChallenge(opts.upstreamResp);

  1. postinstall hook runs npm install --prefix captcha_node --omit=dev on every bun install. The project runtime is Bun and npm may not exist in Bun-only/CI/offline environments. This breaks installs for users who never use start-plan captcha. Consider making the sub-install lazy (run on first solve) or documenting the Node requirement.

"start": "bun run src/index.ts",
"test": "bun test",

  1. isCaptchaFailure(resp) treats any HTTP 403 or 405 response, or any response body containing "captcha"/"3007"/"3012", as a captcha failure. Previously, retry only triggered on the explicit x-aliyun-captcha-verify-param response header. Non-captcha 403 errors (auth, quota, rate limit) will now be misclassified, triggering unnecessary re-solves and masking the real upstream error behind captcha_verification_failed.

}
async function isCaptchaFailure(resp: Response): Promise<boolean> {
if (resp.status === 403 || resp.status === 405) return true;
const text = await resp.clone().text().catch(() => "");
const low = text.toLowerCase();

  1. normalizeUserSystem() in system-prompt.ts calls .trim() on b.text without verifying it is a string. A malformed Anthropic system block like { type: "text", text: 123 } throws TypeError. This violates the body-transformer's "fail open" contract since the exception is not caught by the transform path (only JSON.parse is wrapped).

const b = item as SystemBlock;
if ((b.text || "").trim()) {
out.push({

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@TriDefender

Copy link
Copy Markdown
Owner

There's one useful thing tho, upstream needs Authorization: Bearer {jwt}, which is different from current code. I'm currently checking with original zcode source file to see the exact usage

@TriDefender

TriDefender commented Jun 20, 2026 •

Copy link
Copy Markdown
Owner

R5("buildStartPlanRuntimeAuthorizationHeaders") — Only works on zaiStartPlan / bigmodelStartPlan provider ,returns{ Authorization: "Bearer {jwt}" },
Noted, thanks!

@TriDefender

Copy link
Copy Markdown
Owner

Hey I will push some new updates into the auto-captcha branch soon and hope you will test then. I did learn two items from your PR, the Bearer JWT and the json prompt file instead of hardcoding are both nice to have.

However before actually pushing I would like to have more information of that system-prompt thing on zcode.

  • Is it only applied to start-plan users? Because in coding-plan I did not see errors even if no zcode prompt is injected
  • If it won't error on coding-plan, did you have intel on whether it will make the 150% usage discount on glm-5.2 invalid?

I know it may be too much to ask and indeed it's hard to prove.

@yurchik228336

Copy link
Copy Markdown
Contributor Author
  1. Start-plan only?
    Yes. In my PR the injection is gated on plan === "start-plan" only. I did not apply it for coding-plan — that path hits a different upstream (api.z.ai/...), uses api-key auth instead of JWT, and I never saw 3012 there when omitting those blocks. The failure I hit was specific to zcode.z.ai/api/v1/zcode-plan/anthropic/v1/messages: valid captcha but missing the two official gateway blocks at system[0] and system[1] → HTTP 405 / code 3012.

  2. About the 150% GLM-5.2 discount
    Honestly: I can’t prove either way. I didn’t run A/B billing tests on coding-plan with these blocks injected. The JSON content mirrors what the official ZCode desktop client sends on the start-plan route — I’m reproducing client behavior, not inventing a new prompt. I wouldn’t recommend applying it on coding-plan anyway: different endpoint, different validation, and extra input tokens for no clear benefit on that path.

  3. What I’m confident about
    Start-plan without the official blocks → 3012 even with a solved captcha; with blocks + captcha + Bearer → HTTP 200 in my live test before opening the PR. Coding-plan without injection worked fine in my setup.

@TriDefender

Copy link
Copy Markdown
Owner
  1. Start-plan only?
    Yes. In my PR the injection is gated on plan === "start-plan" only. I did not apply it for coding-plan — that path hits a different upstream (api.z.ai/...), uses api-key auth instead of JWT, and I never saw 3012 there when omitting those blocks. The failure I hit was specific to zcode.z.ai/api/v1/zcode-plan/anthropic/v1/messages: valid captcha but missing the two official gateway blocks at system[0] and system[1] → HTTP 405 / code 3012.
  2. About the 150% GLM-5.2 discount
    Honestly: I can’t prove either way. I didn’t run A/B billing tests on coding-plan with these blocks injected. The JSON content mirrors what the official ZCode desktop client sends on the start-plan route — I’m reproducing client behavior, not inventing a new prompt. I wouldn’t recommend applying it on coding-plan anyway: different endpoint, different validation, and extra input tokens for no clear benefit on that path.
  3. What I’m confident about
    Start-plan without the official blocks → 3012 even with a solved captcha; with blocks + captcha + Bearer → HTTP 200 in my live test before opening the PR. Coding-plan without injection worked fine in my setup.

Agreed with actual results, coding plan does not require sys prompt injection, I would gather community A/B test results to see. Since GLM billing had always been obscure: They always uses words like 20x lite usage which is not useful at all

@TriDefender

Copy link
Copy Markdown
Owner

Incorporated commit inspired by your ideas, contribution acknowleged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants